package top.xana.acg.anime.network

import top.xana.acg.anime.SearchSource
import top.xana.acg.parser.BimiAcgParser
import top.xana.acg.parser.MalimaliParser

/**
 * @author xana
 * @date 2022/5/20 0020 16:52
 * @email cv4096@qq.com
 * TODO json from remote server
 **/


class AnimeApi {
    private val bimi = BimiAcgParser()

    private val mali = MalimaliParser()

    fun fetchBanner() = mali.getBanner()

    fun fetchHot() = mali.getHot()

    fun fetHomeBody() = bimi.getHomeBody()

    fun search(searchSource: SearchSource, keyword: String, page: Int = 0) =
        when (searchSource) {
            SearchSource.Bimi -> bimi.search(keyword, page)
            SearchSource.Mali -> mali.search(keyword, page)
        }

    fun fetchDetail(searchSource: SearchSource, uri: String) = when (searchSource) {
        SearchSource.Bimi -> bimi.detail(uri)
        SearchSource.Mali -> mali.detail(uri)
    }

    fun fetchSource(searchSource: SearchSource, uri: String) = when (searchSource) {
        SearchSource.Bimi -> bimi.source(uri)
        SearchSource.Mali -> mali.source(uri)
    }

    fun fetchFavor(searchSource: SearchSource, uri: String) = when (searchSource) {
        SearchSource.Bimi -> bimi.favor(uri)

        SearchSource.Mali -> mali.favor(uri)
    }

    fun fetchPlayUrl(searchSource: SearchSource, uri: String) = when (searchSource) {
        SearchSource.Bimi -> bimi.playUrl(uri)

        SearchSource.Mali -> mali.playUrl(uri)
    }

    suspend fun fetchTimeline() = bimi.timeline()

    fun fetchCategory(
        i: Int = 0,
        o: Int = 0,
        type: String = "",
        alpha: String = "",
        p: Int = 1,
        season: String = "",
        year: String = ""
    ) = bimi.category(i, o, type, alpha, p, season, year)
}
